<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>昨天作业</title>
</head>
<body>
    <script>
        //1.将字符串 “hello” 逆序输出为 “olleh”
        var str1 = "hello"
        var res1 = ''
        for(var i=str1.length-1; i>=0;i--){
            res1 += str1[i]
        }
        
        var str2 = "012c3d4e";
        // var res2 = str2.replace(/\d/g,'');

        var count = 0;//替换的次数
        for(var i=0; i<str2.length;i++){
            console.log(`循环的索引为${i}`)
            //判断是否是数字
            if(!isNaN(str2[i])){
                count++;
                console.log(`第${count}次替换`) 
                console.log(`本次替换的数字是${str2[i]}`)
                //str2 = str2.replace(str2[i],'')
                var r = str2.replace(str2[i],'')
                str2 = r
                console.log('本次替换结果str2的值')
                console.log(str2)
                i-=1; 
            }
        }
        console.log('最终str2的结果')
        console.log(str2)

        //判断一个字符是否是数字
        var n = '1'
        //1. isNaN(n)
        //2. Number(n) == n
        //3. n.charCodeAt() >= 48 && n.charCodeAt() <=57
        //4. numstr = '1234567890'
        //n.indexOf(numstr) != -1
        //5. parseInt(n) == n

        //3. 定义一个字符串 ”CHINESE“，将其输出为 “Chinese“ 
        var str3 = "CHINESE"
        var firstLetter = str3[0].toUpperCase()
        var restLestters = str3.slice(1).toLowerCase()
        var res3 = firstLetter + restLestters

        //统计 ”warriors” 单词中，“r“字母出现的次数
        var count = 0;
        var str4 = "warriors"
        for(var i=0;i<str4.length;i++){
            if(str4.charAt(i) == 'r'){
                count++
            }
        }
        //5. 将字符串 ”-_-” 中的 “-“ 替换成 ”$”
        var str5 = "-_--__-+-";
        // for(var i=0; i<str5.length; i++){
        //     if(str5.charAt(i) == '-'){
        //         str5 = str5.replace('-','$')
        //     }
        // }
        // console.log(str5)

        // while(str5.includes('-')){
        //     str5 = str5.replace('-','$')
        // }
        // console.log(str5)
        // var array5 = str5.split('')
        // console.log(array5)
        // for(var i in array5){
        //     if(array5[i] == '-'){
        //         array5[i] = '$'
        //     }
        // }
        // var res5 = array5.join('')
        "__" +'$'+"-__-+-"
        for(var i=0; i<str5.length; i++){
            if(str5.charAt(i) == '-'){
                var strLeft = str5.slice(0,i)
                var strRigth = str5.slice(i+1)
                str5 = strLeft + '$' + strRigth
            }
        }




    </script>
</body>
</html>